using System;
using System.Collections.Generic;
using System.Text;

namespace RapidHDL
{
    class ScriptHelper
    {

        RapidHardware oRapidHardware;
        System.IO.TextWriter oTextWriter;

        public ScriptHelper(RapidHardware poRapidHardware)
        {
            oRapidHardware = poRapidHardware;
        }

        public void NewFile(string psFileName)
        {
            string sPath = oRapidHardware.Settings.OutputPath; // +@"temp\";
            oTextWriter = TextFile.OpenFileReWrite(sPath, psFileName);
        }


        public void WriteLine(string psValue)
        {
            WriteLine(psValue, 0);
        }

        public void WriteLine(string psValue, int piIndent)
        {
            oTextWriter.WriteLine(new string(' ', piIndent * 5) + psValue);
        }

        public string BuildString(string psResult, string psValue, int piIndent)
        {
            return psResult + "\n" + new string(' ', piIndent * 5) + psValue;
        }

        public string RemoveStringEnding(string psInput, int piRemove)
        {
            if (piRemove >= psInput.Length)
                return "";
            return psInput.Substring(0, psInput.Length - piRemove);
        }

        public void BlankLine()
        {
            WriteLine("");
        }

        public string VerilogVector(string psName, int piWidth)
        {
            if (piWidth == 1)
                return psName;

            int iStart = piWidth - 1;
            return "[" + iStart.ToString() + ":0] " + psName;
        }

        public void CloseFile()
        {
            oTextWriter.Close();
        }

    }
}
